<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>

    <style>
        .tab ul {
            overflow: hidden;
            padding: 0;
            margin: 0;
        }

        .tab ul li {
            list-style: none;
            padding: 0;
            float: left;
            width: 100px;
            height: 45px;
            line-height: 45px;
            text-align: center;
            border: 1px solid red;
            cursor: pointer;
        }

        /*当选中的背景色为橙色*/
        .tab ul li.active{
            background-color: orange;
        }

        .tab div {
            width: 500px;
            height: 300px;
            display: none;
            border: 1px solid blue;

        }

        /*让选中的展示出来*/
        .tab div.currentselect {
            display: block;

        }


    </style>
</head>
<body>

<div id="div1">
    
    <div class="tab">

            <ul>
                <!--
                    index 0,1,2
                -->
                <li @click='changeTalSelect(index)' :class='currentIndex==index?"active":""' v-for="(item,index) in products"> {{item.name}}</li>


            </ul>
        
        <div :class='currentIndex==index ?"currentselect":""'  v-for="(item,index) in products">

            <img :src="item.path">
        </div>
    </div>
    
</div>

<script>

    const vueObj = new Vue({
        el:'#div1',
        data: {
            //当前被选中的
            currentIndex: 0,
            products: [
                {
                    id: 1,
                    name: '笔记本电脑',
                    path: 'img/pc.png',
                },
                {
                    id: 2,
                    name: '厨具',
                    path: 'img/chuju.png',
                },
                {
                    id: 3,
                    name: '家电',
                    path: 'img/jiadian.png',
                },

            ]
        },
        methods:{
            changeTalSelect:function (index){
                this.currentIndex = index;
            }
        }

    });
</script>
</body>
</html>